package org.xzx.shop_api.entity;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;

/**
 * 资讯实体类（对应ES索引）
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Document(indexName = "news_index")  // 关联索引名
public class News {
    @Id
    @Field(name = "id",type = FieldType.Keyword)
    private int id;

    @Field(type = FieldType.Text, analyzer = "ik_analyzer", searchAnalyzer = "ik_analyzer")
    private String title;  // 标题（IK分词）

    @Field(type = FieldType.Text, analyzer = "ik_analyzer", searchAnalyzer = "ik_analyzer")
    private String content;  // 内容（IK分词）

    @JsonProperty("create_time")
    @Field(name = "create_time", type = FieldType.Integer)
    private int createTime;

    @Override
    public String toString() {
        return "News{" +
                "id='" + id + '\'' +
                ", title='" + title + '\'' +
                ", content='" + content + '\'' +
                ", createTime=" + createTime +
                '}';
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getCreateTime() {
        return createTime;
    }

    public void setCreateTime(int createTime) {
        this.createTime = createTime;
    }
}